package com.base.config.listener;

        import org.slf4j.Logger;
        import org.slf4j.LoggerFactory;

        import javax.servlet.ServletContextEvent;
        import javax.servlet.ServletContextListener;
        import javax.servlet.ServletRequestEvent;
        import javax.servlet.ServletRequestListener;
        import javax.servlet.annotation.WebListener;
        import javax.servlet.http.HttpSessionEvent;
        import javax.servlet.http.HttpSessionListener;

/**
 * 开发公司：个人
 * 版权：个人
 * <p>
 * Listener
 *
 * @author 刘志强
 * @created Create Time: 2019/5/25
 */

@WebListener()
public class Listener implements ServletRequestListener, HttpSessionListener,ServletContextListener  {

    protected Logger logger = LoggerFactory.getLogger(getClass());
    // ServletRequestListener start
    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        logger.info("监听器到" + servletRequestEvent.getServletRequest().getServerName() + "被销毁");
    }

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        logger.info("监听器到" + servletRequestEvent.getServletRequest().getServerName() + "被创建");
    }
    // ServletRequestListener end

    // HttpSessionListener start
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
        logger.info("监听器到" + httpSessionEvent.getSession().getId() + "被创建");
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
        logger.info("监听器到" + httpSessionEvent.getSession().getId() + "被销毁");
    }
    // HttpSessionListener end

    // ServletContextListener start
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        logger.info("监听器到" + servletContextEvent.getServletContext().getServerInfo() + "被创建");
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
        logger.info("监听器到" + servletContextEvent.getServletContext().getContextPath() + "被销毁");
    }
    // ServletContextListener end


}